package com.hejia.alauda.entity;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;

/**
 * 金融资产库存记录
 * 
 * @author hyr
 *
 */
public class FinancialAssetStockEntry extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 564662701631071952L;

	@Column
	private FinancialAsset financialAsset; // 金融资产
	@Column
	private Purpose purpose; // 用途
	@Column
	private Type type; // 类型
	@Column
	private Date postingDate; // 出入库日期
	@Column
	private BigDecimal amount; // 金额
	@Column
	private Product product; // 产品

	public FinancialAsset getFinancialAsset() {
		return financialAsset;
	}

	public void setFinancialAsset(FinancialAsset financialAsset) {
		this.financialAsset = financialAsset;
	}

	public Purpose getPurpose() {
		return purpose;
	}

	public void setPurpose(Purpose purpose) {
		this.purpose = purpose;
	}
	
	public String getPurposeDescription(){
		if(this.purpose == null){
			return "";
		}
		return this.purpose.getDescription();
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}
	
	public String getTypeDescription(){
		if(this.type == null){
			return "";
		}
		return this.type.getDescription();
	}

	public Date getPostingDate() {
		return postingDate;
	}

	public void setPostingDate(Date postingDate) {
		this.postingDate = postingDate;
	}

	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	/**
	 * 库存记录类型
	 * 
	 * @author hyr
	 *
	 */
	public enum Type {
		
		/**
		 * 入库
		 */
		In,

		/**
		 * 出库
		 */
		Out;

		/**
		 * 获取描述
		 * @return	描述
		 */
		public String getDescription() {
			
			String description = "";
			
			switch(this){
			case In:
			description = "入库";
			break;
			
			case Out:
			description = "出库";
			break;
			}
			
			return description;
		}
	}

	/**
	 * 出入库资金用途
	 * 
	 * @author hyr
	 *
	 */
	public enum Purpose {
		
		/**
		 * 新金融资产
		 */
		NewFinancialAsset(Type.In),

		/**
		 * 发售产品
		 */
		Sale(Type.Out),

		/**
		 * 删除产品
		 */
		DeleteProduct(Type.In),
		
		/**
		 * 结束销售，余额入库
		 */
		SoldInStock(Type.In),
		
		/**
		 * 超卖，超出金额出库
		 */
		Oversell(Type.Out),

		/**
		 * 用户回款
		 */
		PaymentCollection(Type.In);
		
		private Type type; // 类型
		
		private Purpose(Type type) {
			this.type = type;
		}
		
		public Type getType() {
			return this.type;
		}
		
	     /**
	      * 获取描述
	      * @return	描述
	      */
		public String getDescription(){
			
			String description = "未知";
			
			switch(this){
			case NewFinancialAsset:
				description = "新金融资产";
				break;
			case Sale:
				description = "发售产品";
				break;
			case DeleteProduct:
				description = "删除产品";
				break;
			case SoldInStock:
				description = "售完";
				break;
			case PaymentCollection:
				description = "用户回款";
				break;
			case Oversell:
				description = "超卖";
				break;
			default:
				break;
			}
			
			return description;
		}
	}
}
